package com.xique.system.service.biz.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.system.bean.domain.Area;
import com.xique.system.bean.request.AreaCodeListRequest;
import com.xique.system.service.biz.IAreaBizService;
import com.xique.system.service.service.IAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shd
 * @create 2022/3/15 14:16
 */
@Service
public class AreaBizServiceImpl implements IAreaBizService {

    @Autowired
    private IAreaService areaService;

    @Override
    public AjaxResult getAreaCodeList(AreaCodeListRequest request) {

        Long parentId = -1L;
        if (!"000000".equals(request.getCode())) {
            QueryWrapper<Area> condition = new QueryWrapper<>();
            condition.eq("area_code", request.getCode());
            Area area = areaService.getOne(condition);

            parentId = area.getAreaId();
        }

        QueryWrapper<Area> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id", parentId);
        List<Area> list = areaService.list(wrapper);

        return AjaxResult.success(list);
    }
}
